package com.sztz.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.sztz.vo.wx.WxSignVo;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 微信开发平台相关的工具类
 * @author yzy
 * @date 2023/2/8 16:53
 */
public class WxUtils {
    /**
     * 微信开发平台接口配置时的Token
     */
    private static final String WX_TOKEN = "yzy_test_0208";
    /**
     * 微信AppId
     */
    private static final String APP_ID="wxb077e6fcfa297989";
    /**
     * 微信AppSecret
     */
    private static final String APP_SECRET="e16873179d6f15ad923c75484436491d";
    /**
     * 微信开发平台接口接口参数配置时token验证
     * @author yzy
     * @date 2023/2/8 16:53
     */
    public static boolean checkSign(WxSignVo wxSignVo){
        String dataStr = Stream.of(WX_TOKEN, wxSignVo.getTimestamp(), wxSignVo.getNonce()).sorted().collect(Collectors.joining());
        return StrUtil.equalsAnyIgnoreCase(SecureUtil.sha1(dataStr),wxSignVo.getSignature());
    }
}
